calculating mean from frequency table